//
//  LoginStepOneVC.m
//  BrushFace
//
//  Created by Zzz on 15/11/29.
//  Copyright © 2015年 Zzz. All rights reserved.
//

#import "LoginStepOneVC.h"
#import "LoginViewModel.h"
#import "LoginRequest.h"
#import "NavHelper.h"
#import "IQTextView.h"

@interface LoginStepOneVC ()
@property (weak, nonatomic) IBOutlet UITextField *mpUserNameTextView;
@property (weak, nonatomic) IBOutlet UITextField *mpUserPassWordTextView;
@property (weak, nonatomic) IBOutlet UIButton *mpLoginBtn;

@end

@implementation LoginStepOneVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // 创建UI
    self.mpUserNameTextView.placeholder = @"请输入账号";
    @weakify(self);
    [[self.mpUserNameTextView.rac_textSignal
     filter:^BOOL(NSString * text) {
         @strongify(self);
         return [self checkPassWord:text];
     }]
     subscribeNext:^(NSString * text) {
         ITLogSP(@"%@",text);
     }];
    
    
//    [[[[self.mpLoginBtn
//        rac_signalForControlEvents:UIControlEventTouchUpInside]
//       doNext:^(id x) {
//           self.mpLoginBtn.enabled = NO;
//           self.mpLoginBtn.hidden = YES;
//       }]
//      flattenMap:^id(id x) {
//          return [self signInSignal];
//      }]
//     subscribeNext:^(NSNumber *signedIn) {
//         self.signInButton.enabled = YES;
//         BOOL success = [signedIn boolValue];
//         self.signInFailureText.hidden = success;
//         if (success) {
//             [self performSegueWithIdentifier:@"signInSuccess" sender:self];
//         }
//     }];


    
    /*
    @weakify(self);
    [[RACObserve(self.mpUserIdTextView, text)filter:^BOOL(id value) {
        @strongify(self);
        return self.mpUserIdTextView.text.length != 0;
    }]subscribeNext:^(id x) {
        @strongify(self);
        ITLogSP(@"%@",self.mpUserIdTextView.text);
    }];
    
    self.mpUserIdTextView.placeholder = @"请输入密码";
    [[RACObserve(self.mpUserIdTextView, text)filter:^BOOL(id value) {
        @strongify(self);
        return self.mpUserIdTextView.text.length != 0;
    }]subscribeNext:^(id x) {
        @strongify(self);
        ITLogSP(@"%@",self.mpUserIdTextView.text);
    }];

    // 创建请求
    LoginViewModel * vm = [LoginViewModel SceneModel];
    LoginRequest * rq = [LoginRequest Request];
    [[RACObserve(rq,state)
     filter:^BOOL(id value) {
         return YES;
     }]subscribeNext:^(id x) {
         NSLog(@"--%@",rq.output);
     }];
    [vm SEND_ACTION:rq];*/
}

- (BOOL)checkPassWord:(NSString *)passWord
{
    BOOL isCheckSuccess = passWord.length > 3;
    return isCheckSuccess;
}

- (BOOL)checkUserName:(NSString *)userName
{
    BOOL isCheckSuccess = userName.length > 3;
    return isCheckSuccess;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)clickLogin:(id)sender
{
    [NavHelper gotoFindVC];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
